\documentclass[a4paper,12pt]{article}
\usepackage{matlab-prettifier}
\usepackage{tcolorbox}
\appendix

\tcbuselibrary{listings,skins,breakable,xparse}
\tcbset{%
 mylist/.style = {%
  colframe = gray,
  colback = white,
  coltitle = red!50!yellow!3!white,
  colbacktitle = white,
  listing only,
  attach boxed title to top center = {yshift = -\tcboxedtitleheight/2},
  enhanced,
  drop fuzzy shadow, % shadow around listings
  left = 6.5mm, % distance between left rule and line number 
  breakable, % enable listing box to break by page
  %enhanced jigsaw, % box not being closed when broken by page
  fonttitle=\small\bfseries\color{black}, % customise font of listing title
  before skip=20pt plus 2pt, % vertical space between listings and text
  after skip=20pt plus 2pt,
 },
 example/.style 2 args = {%
  mylist,
  title = {Listing \thetcbcounter: #1},
  label = {#2},
 },
 }
 \newtcblisting[auto counter, number within = section, list inside = mcode]{matlab}[3][]{%
  listing options = {%
   style = Matlab-editor,
   numbers = left,
   numberstyle = \footnotesize\color{darkgray}
  },
  overlay = {\begin{tcbclipinterior}\fill[blue!15!white] (frame.south west) rectangle ([xshift=5.3mm]frame.north west);\end{tcbclipinterior}},
  example = {#2}{#3}, #1,
 }

\begin{document}
%\tcblistof[\section]{mcode}{List of MATLAB code}
\section{First Section}
\begin{matlab}{My 1st Code(Written by MATLAB)}{code:label}
% a comment
clear all, clc
% a comment
x = [1.00; 1.00; 1.00];
beta0 = [1 1 1];
modelfun = 'y ~ k*x^2+b'
mdl = fitnlm(tb,modelfun,beta0)
% a comment
plotResiduals(md1,'fitt111111111111111ed')
%this is a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooog









































































%1
\end{matlab}
\begin{matlab}{My 2st Code}{code:label}
disp('hello')
\end{matlab}
\begin{matlab}{My 2st Code}{code:label}
    disp('hello')
\end{matlab}